
var formidable = require('formidable');

var db = require('../models/db');

var User = require('../models/user');





exports.showIndex = function (req,res,next) {
    res.render('index');


}


exports.showRegist = function (req,res,next) {
    res.render('regist');

}

exports.doRegist = function (req,res,next) {
     var form = new formidable.IncomingForm();
     form.parse(req,function (error,fileds,files) {
         let username = fileds.username;
         let password = fileds.password;

         User.find({'username':username},function(err,result){
             if(err){
                 res.send('-3');
                 return;
             }
             if(result.length > 0){
                 res.send('-1');
                 return;
             }

             new User({
                 username: username,
                 password: password,

             }).save( function( err ){
                 if(err){
                     res.send('2');
                 }else {
                     res.send('1');
                 }
             });



         });



     });


}

